﻿<?php

//session_start();

//if (!isset($_SESSION['kid'])) {
  //  include("startseite.php");
   // exit();
//}
//$_SESSION['gastzahl'] = $_GET['gz'];

?>

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>offentisch</title>

    <!-- Bootstrap -->
    <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
	<link href="bootstrap/css/style.css" rel="stylesheet">
	<link href="bearbeitung.css" rel="stylesheet">
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
	<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
	<script src="js/jquery-1.11.1.min.js"></script>
	<!-- Include all compiled plugins (below), or include individual files as needed -->
	<script src="bootstrap/js/bootstrap.min.js"></script>
	<script type="text/javascript">
		function time() {
		   var today = new Date();
		   var h=today.getHours();
		   var m=today.getMinutes();
		   var s=today.getSeconds();
		   m=checkTime(m);
		   s=checkTime(s);
		   nowTime = h+":"+m+":"+s;
		   //if(dd<10){dd='0'+dd} if(mm<10){mm='0'+mm} today = day+', '+ dd+'-'+mm+'-'+yyyy;
			tmp='<span class="date">'+nowTime+'</span>';
		   document.getElementById("clock").innerHTML=tmp;
		   clocktime=setTimeout("time()","1000","JavaScript");
		   function checkTime(i){
			  if(i<10){
			 i="0" + i;
			  }
			  return i;
		   }
		}
		</script>
		<script type="text/javascript">
		$(document).ready(function(){
			$('t').click(function(){
				//var tischid=parseInt($(this).attr('id'));
				document.location="gerufentisch.php?id="+ parseInt($(this).attr('id'));
			});
		});
	</script>
	</head>
	<body onload="time()">

	<div class= "container">
		<div class= "jumbotron" style = "background-color: #341256; text-align: center;">
				<p style = "color: white; font-size: 50px;">  Nam Bộ Restaurant</p>
				<p class="alert alert-success"style = "font-size: 25px;color:#113118;">  Offene Tische</p>
		</div>
		<div class= "jumbotron" style = "background-color: #341256; text-align: center;">
			
			<div class= "row" style = "background-color: #524064;">
				<div class="col-xs-6 col-md-9" style ="overflow: auto;">
					<?php
						showTables();
					?>
				<br>
				</div>	
				
				<div class="col-md-3" style = "background-color: #757b42">
					
						
						<div class= "row">
							<a class="btn btn-danger btn-lg btn-block" role="button" style ="font-size: 25px;"><br>Buchungsbereit<br><br></a>
							<br>
							<a href="bearbeitung.php" class="btn btn-success btn-lg btn-block" role="button" style ="font-size: 25px;"><br>Zurück<br><br></a>
							<br>
							<a class="btn btn-warning btn-lg btn-block" role="button" style ="font-size: 25px;">
								<br>
								<p id ="clock" style = "color: white;"></p>
							</a>
						</div>	
					
				</div>				
			</div>
		</div>
	</div>
	 	
	</body>
</html>

<?php

function showTables(){
	require_once("db/connectDB.php");
	$j=4;
	$i=0;
	$result = mysql_query("SELECT * FROM tische") or die (mysql_error());
	if (mysql_num_rows($result) == 0){
		echo "<h1> keinen offenen Tisch vorhanden</h1>";
		
	}
	else{
		while ($row= mysql_fetch_array($result)){
			if($i==0 ||$i==$j){
				if($i==$j) {
					$j=4+$j;
				}
				echo "<div  class= 'row'>";
				echo "<div class= 'col-xs-6 col-md-3'>";
				echo "<t id =".$row['id']."type= 'button' class='btn btn-success btn-lg btn-block' style ='font-size: 15px;'><br>Tisch ".$row['tischnr']."<br><br></t>";
				echo "</div>";
				$i++;
			}
			else{
				echo "<div  class= 'col-xs-6 col-md-3'>";
				echo "<t id =".$row['id']." type= 'button' class='btn btn-success btn-lg btn-block' style ='font-size: 15px;'><br>Tisch ".$row['tischnr']."<br><br></t>";
				echo "</div>";
				if($i==($j-1)){
					echo "</div>";
					
					echo "<br>";
				}
				
				$i++;
			} 
		}
		echo "</div>";
		mysql_free_result($result);	
	}
}

?>